#include<stdio.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#include<errno.h>
#include<string.h>
int main()
{
  pid_t id = fork();
  pid_t status = 0;
  if(id == 0)
  {
    int cnt = 5;
    while(cnt)
    {
    printf("I am child process pid: %d,ppid: %d\n",getpid(),getppid());
    sleep(1);
    cnt--;
    }
  }
  else if(id < 0) printf("errno : %d , strerror: %s\n",errno,strerror(errno));
  else 
  {
    while(1)
    {
      sleep(1);
    //pid_t rid = wait(&status);
    pid_t rid = waitpid(id,&status,0);
    printf("I am parent process pid: %d,ppid: %d,wait: %d,exit: %d\n",getpid(),getppid(),rid,WEXITSTATUS(status));

    //printf("I am parent process pid: %d,ppid: %d,\n",getpid(),getppid());
    }
  }
  return 0;
}
